package net.wanho.zaixian.course.service.impl;

import net.wanho.zaixian.course.dao.CourseBaseDao;
import net.wanho.zaixian.course.service.CourseBaseService;
import net.wanho.zaixian.pojo.course.CourseBase;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import java.util.List;
import java.util.Optional;

@Service
public class CourseBaseServiceImpl implements CourseBaseService {

    @Resource
    private CourseBaseDao courseBaseDao;
    @Override
    public List<CourseBase> findAllByPage(Pageable pageable) {

        Page<CourseBase> courseBasePage = courseBaseDao.findAll(pageable);
        return courseBasePage.toList();
    }

    @Override
    public List<CourseBase> findAll() {
        List<CourseBase> all = courseBaseDao.findAll();
        return all;
    }

    @Override
    public void addCourseBase(CourseBase courseBase) {
        courseBaseDao.save(courseBase);
    }

    /**
     * 根据id查询课程
     * @param courseId
     * @return
     */
    @Override
    public CourseBase getCourseBaseById(String courseId) {
        Optional<CourseBase> optional = courseBaseDao.findById(courseId);
        if(optional !=null && optional.isPresent()){
            CourseBase courseBase = optional.get();
            return courseBase;

        }
        return null;
    }

    /**
     * 修改课程
     * @param courseBase
     */
    @Override
    public void updateCourseBase(CourseBase courseBase) {
        CourseBase save = courseBaseDao.save(courseBase);
        System.out.println(save);


    }
}
